import cv2
import numpy as np
import singletonBlock
import pickle

if __name__ == "__main__":
    with open('./model/model_0.bin', 'rb') as f:
        gmm = pickle.loads(f.read())

    for i in range(40):
        # 全局定义读取图像
        initImg = cv2.imread("./data/data_{}.jpg".format(i))
        # 灰度化图像
        imgGray = singletonBlock.rgb2gray(initImg)
        # r: 阈值, b: 二值化图像, 大津法
        r, b = singletonBlock.binary_ostu(imgGray)

        gmmModel = singletonBlock.get_plantZone(gmm, initImg, initImg.shape[0], initImg.shape[1])

        singletonBlock.print_ratio_percent(b, i)
        singletonBlock.print_ratio_percent_remove_plant(b, gmmModel, i)

    cv2.waitKey(0)
    cv2.destroyAllWindows()

    # ------ 设置打印是完整打印 --------
    np.set_printoptions(threshold=np.inf)
